package com.lgx.mall.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lgx.common.web.Constants;
import com.lgx.common.web.Pagination;
import com.lgx.mall.core.service.IProductService;
import com.lgx.mall.core.vo.ProductVO;
import com.lgx.mall.view.entity.WebPageDetail;
import com.lgx.mall.view.service.IWebPageDetailService;

/**
 * 共享奢品
 * 
 * @author acer
 *
 */
@Controller
@RequestMapping("/luxury")
public class LuxuryController {

	@Autowired
	private IWebPageDetailService webPageDetailService;
	@Autowired
	private IProductService productService;
	
	public IProductService getProductService() {
		return productService;
	}

	public void setProductService(IProductService productService) {
		this.productService = productService;
	}

	public IWebPageDetailService getWebPageDetailService() {
		return webPageDetailService;
	}

	public void setWebPageDetailService(IWebPageDetailService webPageDetailService) {
		this.webPageDetailService = webPageDetailService;
	}

	@RequestMapping("/index.htm")
	public String index(HttpServletRequest request,HttpServletResponse response){
		
		String brandId = request.getParameter("brandId");
		if(StringUtils.isEmpty(brandId))brandId = "1";
		request.setAttribute("brandId", brandId);
		
		String pageNo = request.getParameter("pageNo");
		if(StringUtils.isEmpty(pageNo))pageNo = "1";
		request.setAttribute("pageNo", pageNo);
		
		return "luxury/index";
	}
	
	@RequestMapping("/head.ftl")
	public String head(HttpServletRequest request,HttpServletResponse response){
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		return "luxury/head";
	}
	
	/**
	 * 奢品（切换）
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/luxury-switch.ftl")
	public String luxurySwitch(HttpServletRequest request,HttpServletResponse response){
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		long categoryId = 123;
		List<ProductVO> details = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		request.setAttribute("details", details);
		
		return "luxury/luxury-switch";
	}
	
	/**
	 * 新增选项卡（奢品）
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/more-luxury.ftl")
	public String moreLuxury(HttpServletRequest request,HttpServletResponse response){
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		String brandId = request.getParameter("brandId");
		String pageNo = request.getParameter("pageNo");
				
		long areaCategory = 4;
		long categoryId = 124;
		
		List<WebPageDetail> details = this.webPageDetailService.findWebPageDetailByAreaAndCid(null, categoryId);
		
		if(details.size() > 0 && StringUtils.isEmpty(brandId)){
			brandId = details.get(0).getEntityId();
		}
		
		Pagination page = this.productService.findProductByCategory(null, areaCategory, 0, Long.parseLong(brandId),null,null,20,Integer.parseInt(pageNo));
		
		request.setAttribute("details", details);
		request.setAttribute("page", page);
		request.setAttribute("areaCategory", areaCategory);
		request.setAttribute("categoryId", categoryId);
		request.setAttribute("brandId", brandId);
		request.setAttribute("pageNo", pageNo);
		return "luxury/more-luxury";
	}
	
	/**
	 * 共享奢品
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/luxury-product.ftl")
	public String luxuryProduct(HttpServletRequest request,HttpServletResponse response){
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);  
		
		long categoryId = 124;
		List<ProductVO> details = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		request.setAttribute("details", details);
		return "luxury/luxury-product";
	}
}
